package top.kaoshanji.p2ch17a;

import java.io.IOException;
import java.nio.file.*;

/**
 * 代码清单-p2ch17a-541页a：查找文件
 * 没有执行
 * author kaoshanji
 * ^_^
 * create time 2025/3/11 17:20
 */
public class Find {

    @SuppressWarnings("resource")
    public static void main(String[] args) throws IOException {
        Path test = Paths.get("test");

        PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**/*.{tmp,txt}");
        Files.walk(test)
                .filter(matcher::matches)
                .forEach(System.out::println);

        System.out.println("***************");

        PathMatcher matcher2 = FileSystems.getDefault().getPathMatcher("glob:*.tmp");
        Files.walk(test)
                .map(Path::getFileName)
                .filter(matcher2::matches)
                .forEach(System.out::println);
        System.out.println("***************");

        Files.walk(test) // 只查找文件
                .filter(Files::isRegularFile)
                .map(Path::getFileName)
                .filter(matcher2::matches)
                .forEach(System.out::println);

    }

}
